package com.sunnystudio.mydiary.data;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class ObjTargetWeight {
	private int id = 0; // ID for local database
	
	private int version_num = 0;
	private double target_grade = 0;
	private double target_braking_distance = 0;
	private double target_coasting = 0;
	private double target_cruise_ctl = 0;
	
	private double target_ecoband_drv = 0;
	private double target_harsh_acceleration = 0;
	private double target_harsh_braking = 0;
	private double target_harsh_cold_drv = 0;
	
	private double target_harsh_throt = 0;
	private double target_idling_percent = 0;
	private double target_overrev = 0;
	private double weight_braking_distance = 0;
	
	private double weight_coasting_distance = 0;
	private double weight_cruise_ctl_distance = 0;
	private double weight_eco_drive_distance = 0;
	private double weight_harsh_acc_distance = 0;
	
	private double weight_harsh_brake_distance = 0;
	private double weight_harsh_cold_drv_distance = 0;
	private double weight_harsh_throt_distance = 0;
	private double weight_idling_time = 0;
	
	private double weight_over_rev_distance = 0;

	public ObjTargetWeight() {
		
	}
	
	/**
	 * Initialize with json string
	 * 
	 * @param String
	 *            json
	 */
	public ObjTargetWeight(String json) {
		try {
			JSONObject obj = new JSONObject(json);
			init(obj);
		} catch (JSONException e) {
			Log.e("ObjShiftAbstract", "Json error: ", e);
		}
	}
	
	/**
	 * Initialize with json object
	 * @param obj
	 */
	public ObjTargetWeight(JSONObject obj) {
		init(obj);
	}
	
	private void init(JSONObject obj) {
		this.version_num = obj.optInt("version_num");
		this.target_grade = obj.optInt("target_grade");
		this.target_braking_distance = obj.optDouble("target_braking_distance");
		this.target_coasting = obj.optDouble("target_coasting");
		this.target_cruise_ctl = obj.optDouble("target_cruise_ctl");
		
		this.target_ecoband_drv = obj.optDouble("target_ecoband_drv");
		this.target_harsh_acceleration = obj.optDouble("target_harsh_acceleration");
		this.target_harsh_braking = obj.optDouble("target_harsh_braking");
		this.target_harsh_cold_drv = obj.optDouble("target_harsh_cold_drv");
		
		this.target_harsh_throt = obj.optDouble("target_harsh_throt");
		this.target_idling_percent = obj.optDouble("target_idling_percent");
		this.target_overrev = obj.optDouble("target_overrev");
		this.weight_braking_distance = obj.optDouble("weight_braking_distance");
		
		this.weight_coasting_distance = obj.optDouble("weight_coasting_distance");
		this.weight_cruise_ctl_distance = obj.optDouble("weight_cruise_ctl_distance");
		this.weight_eco_drive_distance = obj.optDouble("weight_eco_drive_distance");
		this.weight_harsh_acc_distance = obj.optDouble("weight_harsh_acc_distance");
		
		this.weight_harsh_brake_distance = obj.optDouble("weight_harsh_brake_distance");
		this.weight_harsh_cold_drv_distance = obj.optDouble("weight_harsh_cold_drv_distance");
		this.weight_harsh_throt_distance = obj.optDouble("weight_harsh_throt_distance");
		this.weight_idling_time = obj.optDouble("weight_idling_time");
		
		this.weight_over_rev_distance = obj.optDouble("weight_over_rev_distance");
	}
	
	public boolean isValid(){
		boolean isValid = true;
		
		if (this.version_num <= 0) {
			isValid = false;
		}
		
		return isValid;
	}
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the version_num
	 */
	public int getVersion_num() {
		return version_num;
	}

	/**
	 * @param version_num the version_num to set
	 */
	public void setVersion_num(int version_num) {
		this.version_num = version_num;
	}

	/**
	 * @return the target_grade
	 */
	public double getTarget_grade() {
		return target_grade;
	}

	/**
	 * @param target_grade the target_grade to set
	 */
	public void setTarget_grade(double target_grade) {
		this.target_grade = target_grade;
	}

	/**
	 * @return the target_braking_distance
	 */
	public double getTarget_braking_distance() {
		return target_braking_distance;
	}

	/**
	 * @param target_braking_distance the target_braking_distance to set
	 */
	public void setTarget_braking_distance(double target_braking_distance) {
		this.target_braking_distance = target_braking_distance;
	}

	/**
	 * @return the target_coasting
	 */
	public double getTarget_coasting() {
		return target_coasting;
	}

	/**
	 * @param target_coasting the target_coasting to set
	 */
	public void setTarget_coasting(double target_coasting) {
		this.target_coasting = target_coasting;
	}

	/**
	 * @return the target_cruise_ctl
	 */
	public double getTarget_cruise_ctl() {
		return target_cruise_ctl;
	}

	/**
	 * @param target_cruise_ctl the target_cruise_ctl to set
	 */
	public void setTarget_cruise_ctl(double target_cruise_ctl) {
		this.target_cruise_ctl = target_cruise_ctl;
	}

	/**
	 * @return the target_ecoband_drv
	 */
	public double getTarget_ecoband_drv() {
		return target_ecoband_drv;
	}

	/**
	 * @param target_ecoband_drv the target_ecoband_drv to set
	 */
	public void setTarget_ecoband_drv(double target_ecoband_drv) {
		this.target_ecoband_drv = target_ecoband_drv;
	}

	/**
	 * @return the target_harsh_acceleration
	 */
	public double getTarget_harsh_acceleration() {
		return target_harsh_acceleration;
	}

	/**
	 * @param target_harsh_acceleration the target_harsh_acceleration to set
	 */
	public void setTarget_harsh_acceleration(double target_harsh_acceleration) {
		this.target_harsh_acceleration = target_harsh_acceleration;
	}

	/**
	 * @return the target_harsh_braking
	 */
	public double getTarget_harsh_braking() {
		return target_harsh_braking;
	}

	/**
	 * @param target_harsh_braking the target_harsh_braking to set
	 */
	public void setTarget_harsh_braking(double target_harsh_braking) {
		this.target_harsh_braking = target_harsh_braking;
	}

	/**
	 * @return the target_harsh_cold_drv
	 */
	public double getTarget_harsh_cold_drv() {
		return target_harsh_cold_drv;
	}

	/**
	 * @param target_harsh_cold_drv the target_harsh_cold_drv to set
	 */
	public void setTarget_harsh_cold_drv(double target_harsh_cold_drv) {
		this.target_harsh_cold_drv = target_harsh_cold_drv;
	}

	/**
	 * @return the target_harsh_throt
	 */
	public double getTarget_harsh_throt() {
		return target_harsh_throt;
	}

	/**
	 * @param target_harsh_throt the target_harsh_throt to set
	 */
	public void setTarget_harsh_throt(double target_harsh_throt) {
		this.target_harsh_throt = target_harsh_throt;
	}

	/**
	 * @return the target_idling_percent
	 */
	public double getTarget_idling_percent() {
		return target_idling_percent;
	}

	/**
	 * @param target_idling_percent the target_idling_percent to set
	 */
	public void setTarget_idling_percent(double target_idling_percent) {
		this.target_idling_percent = target_idling_percent;
	}

	/**
	 * @return the target_overrev
	 */
	public double getTarget_overrev() {
		return target_overrev;
	}

	/**
	 * @param target_overrev the target_overrev to set
	 */
	public void setTarget_overrev(double target_overrev) {
		this.target_overrev = target_overrev;
	}

	/**
	 * @return the weight_braking_distance
	 */
	public double getWeight_braking_distance() {
		return weight_braking_distance;
	}

	/**
	 * @param weight_braking_distance the weight_braking_distance to set
	 */
	public void setWeight_braking_distance(double weight_braking_distance) {
		this.weight_braking_distance = weight_braking_distance;
	}

	/**
	 * @return the weight_coasting_distance
	 */
	public double getWeight_coasting_distance() {
		return weight_coasting_distance;
	}

	/**
	 * @param weight_coasting_distance the weight_coasting_distance to set
	 */
	public void setWeight_coasting_distance(double weight_coasting_distance) {
		this.weight_coasting_distance = weight_coasting_distance;
	}

	/**
	 * @return the weight_cruise_ctl_distance
	 */
	public double getWeight_cruise_ctl_distance() {
		return weight_cruise_ctl_distance;
	}

	/**
	 * @param weight_cruise_ctl_distance the weight_cruise_ctl_distance to set
	 */
	public void setWeight_cruise_ctl_distance(double weight_cruise_ctl_distance) {
		this.weight_cruise_ctl_distance = weight_cruise_ctl_distance;
	}

	/**
	 * @return the weight_eco_drive_distance
	 */
	public double getWeight_eco_drive_distance() {
		return weight_eco_drive_distance;
	}

	/**
	 * @param weight_eco_drive_distance the weight_eco_drive_distance to set
	 */
	public void setWeight_eco_drive_distance(double weight_eco_drive_distance) {
		this.weight_eco_drive_distance = weight_eco_drive_distance;
	}

	/**
	 * @return the weight_harsh_acc_distance
	 */
	public double getWeight_harsh_acc_distance() {
		return weight_harsh_acc_distance;
	}

	/**
	 * @param weight_harsh_acc_distance the weight_harsh_acc_distance to set
	 */
	public void setWeight_harsh_acc_distance(double weight_harsh_acc_distance) {
		this.weight_harsh_acc_distance = weight_harsh_acc_distance;
	}

	/**
	 * @return the weight_harsh_brake_distance
	 */
	public double getWeight_harsh_brake_distance() {
		return weight_harsh_brake_distance;
	}

	/**
	 * @param weight_harsh_brake_distance the weight_harsh_brake_distance to set
	 */
	public void setWeight_harsh_brake_distance(double weight_harsh_brake_distance) {
		this.weight_harsh_brake_distance = weight_harsh_brake_distance;
	}

	/**
	 * @return the weight_harsh_cold_drv_distance
	 */
	public double getWeight_harsh_cold_drv_distance() {
		return weight_harsh_cold_drv_distance;
	}

	/**
	 * @param weight_harsh_cold_drv_distance the weight_harsh_cold_drv_distance to set
	 */
	public void setWeight_harsh_cold_drv_distance(
			double weight_harsh_cold_drv_distance) {
		this.weight_harsh_cold_drv_distance = weight_harsh_cold_drv_distance;
	}

	/**
	 * @return the weight_harsh_throt_distance
	 */
	public double getWeight_harsh_throt_distance() {
		return weight_harsh_throt_distance;
	}

	/**
	 * @param weight_harsh_throt_distance the weight_harsh_throt_distance to set
	 */
	public void setWeight_harsh_throt_distance(double weight_harsh_throt_distance) {
		this.weight_harsh_throt_distance = weight_harsh_throt_distance;
	}

	/**
	 * @return the weight_idling_time
	 */
	public double getWeight_idling_time() {
		return weight_idling_time;
	}

	/**
	 * @param weight_idling_time the weight_idling_time to set
	 */
	public void setWeight_idling_time(double weight_idling_time) {
		this.weight_idling_time = weight_idling_time;
	}

	/**
	 * @return the weight_over_rev_distance
	 */
	public double getWeight_over_rev_distance() {
		return weight_over_rev_distance;
	}

	/**
	 * @param weight_over_rev_distance the weight_over_rev_distance to set
	 */
	public void setWeight_over_rev_distance(double weight_over_rev_distance) {
		this.weight_over_rev_distance = weight_over_rev_distance;
	}	
	
	public JSONObject toJsonObj()
	{
		JSONObject json = new JSONObject();
		
		try 
		{
			json.put("version_num", version_num );
			json.put( "target_grade", target_grade );
			json.put("target_braking_distance", target_braking_distance );
			json.put("target_coasting", target_coasting );
			json.put("target_cruise_ctl", target_cruise_ctl );
			json.put("target_ecoband_drv", target_ecoband_drv );
			json.put("target_harsh_acceleration", target_harsh_acceleration );
			json.put("target_harsh_braking", target_harsh_braking );
			json.put("target_harsh_cold_drv", target_harsh_cold_drv );
			json.put("target_harsh_throt", target_harsh_throt );
			json.put("target_idling_percent", target_idling_percent );
			json.put("target_overrev", target_overrev );
			json.put("weight_braking_distance", weight_braking_distance );
			json.put("weight_coasting_distance", weight_coasting_distance );
			json.put("weight_cruise_ctl_distance", weight_cruise_ctl_distance );
			json.put("weight_eco_drive_distance", weight_eco_drive_distance );
			json.put("weight_harsh_acc_distance", weight_harsh_acc_distance );
			json.put("weight_harsh_brake_distance", weight_harsh_brake_distance );
			json.put("weight_harsh_cold_drv_distance", weight_harsh_cold_drv_distance );
			json.put("weight_harsh_throt_distance", weight_harsh_throt_distance );
			json.put("weight_idling_time", weight_idling_time );
			json.put("weight_over_rev_distance", weight_over_rev_distance );
		}
		catch( Exception e )
		{
			Log.e("ObjTargetWeight", "Json error", e );
		}
		return json;
	}

	/**
	 * Convert object to json string
	 * 
	 * @return String
	 */
	public String toString() {
		return toJsonObj().toString();
	}
	
}